<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="template_layui :: header(~{::title},~{::link},~{::style})">
    <title>智眼遥感图像识别系统</title>
    <link rel="stylesheet" href="../static/css/login.css">
</head>
<body class="layui-layout-login">
<div class="login-bg">
    <div class="cover"></div>
</div>
<div class="login-content" th:th:classappend="${isCaptcha} ? 'captcha'">
    <h1 class="login-box-title">智眼遥感图像识别系统</h1>
    <form class="layui-form" th:action="@{/login}" method="post">
        <div class="layui-form-item">
            <label class="layui-icon layui-icon-username" for="username"></label>
            <input class="layui-input" type="text" name="username" id="username" placeholder="用户名">
        </div>
        <div class="layui-form-item">
            <label class="layui-icon layui-icon-password" for="password"></label>
            <input class="layui-input" type="password" name="password" id="password" placeholder="密码">
        </div>
        <div class="layui-form-item">
            <input type="checkbox" name="rememberme" title="记住我" lay-skin="primary">
<!--            <a class="layui-layout-right forget-password" href="#">忘记密码?</a>-->
        </div>
        <button type="submit" class="layui-btn layui-btn-fluid ajax-login">登&nbsp;&nbsp;录</button>
    </form>
</div>
<script th:inline="javascript"> var ctx = [[@{/}]]; var captchaType = [[${captchaType}]];
// console.log("ctx",ctx)
</script>
<script th:replace="template_layui :: script"></script>
<script th:inline="javascript">
    if(window.top!==window.self){window.top.location=window.location};
    layui.use(['element'], function () {
        var $ = layui.jquery;

        $(document).on('click', '.ajax-login', function (e) {
            e.preventDefault();

            var username = $("input[name='username']").val();
            var password = $("input[name='password']").val();
            var rememberMe = $("input[name='rememberme']").is(':checked');

            var form = $(this).parents("form");
            var url = form.attr("action");
            var data = {
                "username": username,
                "password": password,
                "rememberMe": rememberMe
                // "rememberMe": true
            };
            $.post(url, data, function (result) {
                if(result.code == 0){
                    console.log("登录成功")
                    location.href = ctx;
                }else{
                    console.log("登录失败"+result.msg)
                    $('.captcha-img').click();
                    $.fn.Messager(result.msg);
                    layer.msg(result.msg);
                }
            });
        })
    });
</script>
</body>
</html>

